/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The software in this package is published under the terms of the GPL v2.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE-GPL.txt file.
 */

package org.cemantika.model;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.cemantika.contextconsumer.ContextConsumerAdapter;

/**
 * ContextConsumerModel represents a context consumer with a focus, which we can retrieve its contextual
 * entities, and a list of elements it is related with.
 * 
 * @author andersonfellipe
 */
public class ContextConsumerModel {

    /**
     * Represents the focus.
     */
    private ContextConsumerAdapter focus;
    /**
     * Represents the list of elements (contextual information) this focus is related with.
     */
    private List<String> elements;

    /**
     * Creates a new instance of ContextConsumerModel.
     */
    public ContextConsumerModel(ContextConsumerAdapter focus, List<String> elements) {
        this.focus = focus;
        this.elements = elements;
    }
    
    /**
     * Creates a new instance of ContextConsumerModel.
     */
    public ContextConsumerModel(ContextConsumerAdapter focus) {
        this.focus = focus;
        this.elements = new LinkedList<String>();
    }

    /**
     * Returns the list of all contextual entities related to the focus.
     * 
     * @return the list of contextual entities.
     */
    public List<Object> getContextualEntities() {
        return focus.getContextualEntities();
    }

    /**
     * Get the focus value.
     * 
     * @return the focus.
     */
    public ContextConsumerAdapter getFocus() {
        return focus;
    }

    /**
     * Get the elements value.
     * 
     * @return the elements.
     */
    public List<String> getElements() {
        return elements;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ContextConsumerModel)) {
            return false;
        }
        ContextConsumerModel other = (ContextConsumerModel) obj;
        return new EqualsBuilder().append(focus, other.focus).isEquals();
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(-806458195, -1310850617).append(focus).toHashCode();
    }

}
